package freemind.controller;

import java.io.Serializable;
import java.util.ArrayList;
import freemind.controller.NodeBean;
import freemind.controller.AtributoEnegModulo;

public class NodeAdapterBase implements NodeAdapterInterface,Serializable{

	private static final long serialVersionUID = 1L;
	
	private NodeBean bean;
	private boolean _isCopied;
	private int nodeCloneId;
	
	private ArrayList<NodeAdapterBase> children;


	public int getId(){return bean.getId();}
	public int getIdParent(){ return bean.getIdParent();}
	public int getIdRaiz(){ return bean.getIdRaiz();}
	public boolean getIsLeft(){ return bean.getLeft();}
	public String getTexto(){ return bean.getTexto(); }
	public int getTipo(){ return bean.getTipo();}
	public int getLink(){ return bean.getLink();}
	public int getCopiaId(){ return bean.getCopiaId(); }
	public int getVirtualId(){ return bean.getVirtualId(); }
	public int getUID(){return bean.getUID();}
	
	public void setId(int id){bean.setId(id);}
	public void setIdParent(int idParent){bean.setIdParent(idParent);}
	public void setIdRaiz(int idRaiz){bean.setIdRaiz(idRaiz);}
	public void setIsLeft(boolean left){bean.setLeft(left);}
	public void setTexto(String texto){bean.setTexto(texto);}
	public void setTipo(int tipo){bean.setTipo(tipo);}
	public void setLink(int link){bean.setLink(link);}
	public void setCopiaId(int copiaId){bean.setCopiaId(copiaId);}
	public void setVirtualId(int virtualId){bean.setVirtualId(virtualId);}	
	public void setUID(int uid){bean.setUID(uid);}	
	
	
	//ServletAttributes	
	
	public void setBean(NodeBean bean){this.bean = bean;}
	public void setLinkString(String l){bean.setLinkString(l);}	
	

	public String getLinkString(){return bean.getLinkString();}
	public NodeBean getBean(){return this.bean;}
	
	public int getCloneId(){return this.nodeCloneId;}	
	public int getEnegModulo(){return 0;}		
	
	
	public void newNode(){bean.newNode();}	
	public void toCreate(){bean.toCreate();}	
	public boolean isVirtual(){return bean.isVirtual();}	
	public boolean isCreated(){return bean.isCreated();}	
	public void hasChanged(){bean.hasChanged();}	
	public void hasSaved(){bean.hasSaved();}
		
	
	public boolean isCopied(){return this._isCopied;}	
	public boolean isACopy(){return this.getCopiaId() > 0;}	
	public void setAsNotCopy(){this.setCopiaId(0);}		
	public boolean isChanged(){return bean.isChanged();}
	public boolean isRoot(){return bean.isRoot();}

	
	public void addAtributoExtra(AtributoEnegModulo attr){
		this.bean.addAtributoExtra(attr);
	}
	
	public ArrayList<AtributoEnegModulo> getAtributosExtras() {
		return this.bean.getAtributosExtras();
	}	
	
	public void clearAtributosExtras(){
		this.bean.clearAtributosExtras();
	}	
	
	public NodeAdapterBase(NodeBean bean){
		this.bean = bean;
		children = new ArrayList<NodeAdapterBase>();
	}
	
	public NodeAdapterBase(){
		this.bean = new NodeBean();
		children = new ArrayList<NodeAdapterBase>();
	}		
	
	
	public void addChild(NodeAdapterBase child){
		this.children.add(child);
	}
	
	public ArrayList<NodeAdapterBase> getChildren(){
		return this.children;
	}		
	
	public void setAsCopied(int nodeCloneId){
		this._isCopied = true;
		this.nodeCloneId = nodeCloneId;
	}
	
	public void setAsNotCopied(){
		this._isCopied = false;
		this.nodeCloneId = 0;
	}		
	
	
	public static NodeAdapterBase getAdapterFromEnegModulo(int eneg_modulo){
		return NodeAdapterBase.getAdapterFromEnegModulo(eneg_modulo,new NodeBean());
	}
	
	public static NodeAdapterBase getAdapterFromEnegModulo(int eneg_modulo,NodeBean bean){
		if( eneg_modulo == NodeAdapterBase.DIALOGO ){
			return new NodeAdapterDialogos(bean);
		}
		else if( eneg_modulo == NodeAdapterBase.RISCOS ){
			return new NodeAdapterRiscos(bean);
		}
		
		return null;
		
	}	
	
}
